#ifndef WIDGET_FUNCE_CONTROL_INDUSTRIAL_H
#define WIDGET_FUNCE_CONTROL_INDUSTRIAL_H

#include <QWidget>
#include <QMediaPlayer>
#include <QNetworkAccessManager>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QListWidgetItem>
#include <QTimer>
#include <QMap>
#include <QNetworkConfigurationManager>
#include <QNetworkSession>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget_funcE_Control_industrial; }
QT_END_NAMESPACE

class Widget_funcE_Control_industrial : public QWidget
{
    Q_OBJECT

public:
    explicit Widget_funcE_Control_industrial(QWidget *parent = nullptr);
    ~Widget_funcE_Control_industrial();

private slots:
    // UI自动连接的槽函数
    void on_searchButton_clicked();
    void on_playButton_clicked();
    void on_pauseButton_clicked();
    void on_stopButton_clicked();
    void on_songList_itemDoubleClicked(QListWidgetItem *item);
    void on_progressSlider_sliderMoved(int position);

    // 手动连接的槽函数
    void updateProgress(qint64 position);
    void updateDuration(qint64 duration);
    void handleSongFinished(QMediaPlayer::State state);

signals:
    void lyricReceived(const QString& lyric);  // 新增信号

private:
    Ui::Widget_funcE_Control_industrial *ui;
    QMediaPlayer *player;
    QNetworkAccessManager *networkManager;
    QMap<QNetworkReply*, QTimer*> replyTimeouts;
    QNetworkSession *networkSession = nullptr;  // 添加这行

    QVector<QPair<QString, QString>> searchResults;
    QMap<qint64, QString> lyricMap;

    void searchMusic(const QString &keyword);
    void playMusicById(const QString &id);
    void fetchLyric(const QString &id);
    void fetchArtistSongs(const QString &artistId);
    void parseLyric(const QString &lyricText);
    void displayCurrentLyric(qint64 position);
    void handleSearchReply(QNetworkReply *reply);
    void handleLyricReply(QNetworkReply *reply);
    void handleArtistSongsReply(QNetworkReply *reply);

};
#endif // WIDGET_FUNCE_CONTROL_INDUSTRIAL_H
